home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_Tix.idb / usr / freeware / lib / tix4.1 / demos / samples / Meter.tcl.z / Meter.tcl
Encoding:
Text File  |  1999-01-26  |  1.9 KB  |  74 lines

  1. # Tix Demostration Program
  2. #
  3. # This sample program is structured in such a way so that it can be
  4. # executed from the Tix demo program "widget": it must have a
  5. # procedure called "RunSample". It should also have the "if" statment
  6. # at the end of this file so that it can be run as a standalone
  7. # program using tixwish.
  8.  
  9. # This program demonstrates the use of the tixMeter widget -- it is
  10. # used to display the progress of a background job
  11. #
  12.  
  13. proc RunSample {w} {
  14.     set top [frame $w.f -bd 1 -relief raised]
  15.     set box [tixButtonBox $w.b -bd 1 -relief raised]
  16.  
  17.     pack $box -side bottom -fill both
  18.     pack $top -side top -fill both -expand yes
  19.  
  20.     # Create the Meter and the Label
  21.     #
  22.     label $top.lab -text "Work in progress ...."
  23.     tixMeter $top.met -value 0 -text 0%
  24.  
  25.     pack $top.lab -side top -padx 50 -pady 10 -anchor c
  26.     pack $top.met -side top -padx 50 -pady 10 -anchor c
  27.  
  28.  
  29.     # Create the buttons
  30.     #
  31.     $box add cancel  -text Cancel  -command "destroy $w" \
  32.     -width 6 -under 0
  33.     $box add restart -text Restart -width 6 -under 0
  34.  
  35.     $box subwidget restart config -command \
  36.     "Meter:Start $top.met [$box subwidget cancel] [$box subwidget restart]"
  37.  
  38.     $box subwidget restart invoke
  39. }
  40.  
  41. proc Meter:Start {meter cancel restart} {
  42.     $restart config -state disabled
  43.     $cancel config -text Cancel
  44.     after 40 Meter:BackgroundJob $meter 0 $cancel $restart
  45. }
  46.  
  47. proc Meter:BackgroundJob {meter progress cancel restart} {
  48.     if ![winfo exists $meter] {
  49.     # the window has already been destroyed    
  50.     #
  51.     return
  52.     }
  53.  
  54.     set progress [expr $progress + 0.02]
  55.     set text [expr int($progress*100.0)]%
  56.  
  57.     $meter config -value $progress -text $text
  58.  
  59.     if {$progress < 1.0} {
  60.     after 40 Meter:BackgroundJob $meter $progress $cancel $restart
  61.     } else {
  62.     $cancel config -text OK -under 0
  63.     $restart config -state normal
  64.     }
  65. }
  66.  
  67. if {![info exists tix_demo_running]} {
  68.     wm withdraw .
  69.     set w .demo
  70.     toplevel $w
  71.     RunSample $w
  72.     bind $w <Destroy> exit
  73. }
  74.